package com.alex.utils;

public class ResultBody<T> {

    private int code;//参考HTTP的状态码
    private boolean result;//返回任务执行的结果：true/false
    private String message;//问题反馈的描述信息
    private T data;//返回的数据

    public ResultBody() {

    }

    public ResultBody(int code, boolean result, String message) {
        this.code = code;
        this.message = message;
        this.result = result;
    }

    public ResultBody(int code, boolean result, String message, T data) {
        this.result = result;
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static ResultBody<?> success() {
        return new ResultBody(Constant.CODE_SUCCESS.getValue(), true, Constant.CODE_SUCCESS.getName());
    }

    public static ResultBody<?> error() {
        return new ResultBody(Constant.CODE_ERROR.getValue(), false, Constant.CODE_ERROR.getName());
    }

    public static ResultBody<?> error(String message) {
        return new ResultBody(Constant.CODE_ERROR.getValue(), false, message);
    }

    public static <T> ResultBody<?> success(T data) {
        return new ResultBody(Constant.CODE_SUCCESS.getValue(), true, Constant.CODE_SUCCESS.getName(), data);
    }

    public static <T> ResultBody<?> success(String message, T data) {
        return new ResultBody(Constant.CODE_SUCCESS.getValue(), true, message, data);
    }

    public static <T> ResultBody<?> success(String message) {
        return new ResultBody(Constant.CODE_SUCCESS.getValue(), true, message);
    }

    public static <T> ResultBody<?> success(int code, boolean result, String message, T data) {
        return new ResultBody(code, true, message, data);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public boolean isResult() {
        return result;
    }

    public void setResult(boolean result) {
        this.result = result;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
